From c1cabed9fef76cad44fe0095a1ae5be8622202a6 Mon Sep 17 00:00:00 2001 From: robertlipe Date: Sun, 2 Jun 2013 19:15:26 +0000 Subject: [PATCH] Add configlog option to Skytraq. --- gpsbabel/skytraq.cc | 64 +++++++++++++++++++ .../formats/options/skytraq-configlog.xml | 25 ++++++++ 2 files changed, 89 insertions(+) create mode 100644 gpsbabel/xmldoc/formats/options/skytraq-configlog.xml diff --git a/gpsbabel/skytraq.cc b/gpsbabel/skytraq.cc index 05f1fe926..9b6a71579 100644 --- a/gpsbabel/skytraq.cc +++ b/gpsbabel/skytraq.cc @@ -67,6 +67,7 @@ static char *opt_last_sector = 0; /* last sector to be read from the device (def static char *opt_dump_file = 0; /* dump raw data to this file (optional) */ static char *opt_no_output = 0; /* disable output? (0/1) */ static char *opt_set_location = 0; /* set if the "targetlocation" options was used */ +static char *opt_configure_logging = 0; static arglist_t skytraq_args[] = { @@ -78,6 +79,10 @@ arglist_t skytraq_args[] = { "targetlocation", &opt_set_location, "Set location finder target location as lat,lng", "", ARGTYPE_STRING, "", "" }, + { + "configlog", &opt_configure_logging, "Configure logging parameter as tmin:tmax:dmin:dmax", + "", ARGTYPE_STRING, "", "" + }, { "baud", &opt_dlbaud, "Baud rate used for download", "230400", ARGTYPE_INT, "0", "230400" @@ -470,6 +475,43 @@ skytraq_set_baud(int baud) return res_OK; } +static int +skytraq_configure_logging(void) +{ + // an0008-1.4.14: logs if + // (dt > tmin & dd >= dmin & v >= vmin) | dt > tmax | dd > dmax | v > vmax + unsigned int tmin=6, tmax=3600, dmin=0, dmax=10000, nn=0; + gbuint8 MSG_LOG_CONFIGURE_CONTROL[] = { + 0x18, // message_id + 0x00, 0x00, 0x0e, 0x10, // max_time: was 0x0000ffff (big endian!) + 0x00, 0x00, 0x00, 0x06, // min_time: was 0x00000005 + 0x00, 0x00, 0x27, 0x10, // max_distance: was 0x0000ffff + 0x00, 0x00, 0x00, 0x00, // min_distance + 0x00, 0x00, 0xff, 0xff, // max_speed + 0x00, 0x00, 0x00, 0x00, // min_speed + 0x01, // datalog_enable: NOTE: always ON + 0x00 // reserved + }; + + if(opt_configure_logging) { + if(*opt_configure_logging) { + nn = sscanf(opt_configure_logging, "%u:%u:%u:%u", &tmin, &tmax, &dmin, &dmax); + if(nn>3) { + db(0, "Reconfiguring logging to: tmin=%u, tmax=%u, dmin=%u, dmax=%u\n", tmin, tmax, dmin, dmax ); + be_write32(MSG_LOG_CONFIGURE_CONTROL+5, tmin); + be_write32(MSG_LOG_CONFIGURE_CONTROL+1, tmax); + be_write32(MSG_LOG_CONFIGURE_CONTROL+13, dmin); + be_write32(MSG_LOG_CONFIGURE_CONTROL+9, dmax); + } else { + db(1, MYNAME "Option usage: configlog=tmin:tmax:dmin:dmax"); + return -1; + } + } + } + + return skytraq_wr_msg_verify(MSG_LOG_CONFIGURE_CONTROL, sizeof(MSG_LOG_CONFIGURE_CONTROL)); +} + static int skytraq_get_log_buffer_status(gbuint32 *log_wr_ptr, gbuint16 *sectors_free, gbuint16 *sectors_total) { @@ -479,6 +521,8 @@ skytraq_get_log_buffer_status(gbuint32 *log_wr_ptr, gbuint16 *sectors_free, gbui gbuint8 log_wr_ptr[4]; gbuint8 sectors_free[2]; gbuint8 sectors_total[2]; + gbuint8 max_time[4], min_time[4], max_dist[4], min_dist[4], max_speed[4], min_speed[4]; + gbuint8 datalog_enable[1], log_fifo_mode[1]; } MSG_LOG_STATUS_OUTPUT; unsigned int rc; @@ -497,6 +541,21 @@ skytraq_get_log_buffer_status(gbuint32 *log_wr_ptr, gbuint16 *sectors_free, gbui *sectors_free = le_readu16(&MSG_LOG_STATUS_OUTPUT.sectors_free); *sectors_total = le_readu16(&MSG_LOG_STATUS_OUTPUT.sectors_total); + // print logging parameters -- useful, but does this belong here? + unsigned int tmax, tmin, dmax, dmin, vmax, vmin; + // unsigned char log_bool, fifo_mode; + char* mystatus; + tmax = le_readu32(&MSG_LOG_STATUS_OUTPUT.max_time); + tmin = le_readu32(&MSG_LOG_STATUS_OUTPUT.min_time); + dmax = le_readu32(&MSG_LOG_STATUS_OUTPUT.max_dist); + dmin = le_readu32(&MSG_LOG_STATUS_OUTPUT.min_dist); + vmax = le_readu32(&MSG_LOG_STATUS_OUTPUT.max_speed); + vmin = le_readu32(&MSG_LOG_STATUS_OUTPUT.min_speed); + // log_bool = *(MSG_LOG_STATUS_OUTPUT.datalog_enable); + // fifo_mode = *(MSG_LOG_STATUS_OUTPUT.log_fifo_mode); + xasprintf(&mystatus, "#logging: tmin=%u, tmax=%u, dmin=%u, dmax=%u, vmin=%u, vmax=%u\n", tmin, tmax, dmin, dmax, vmin, vmax); + db(1, mystatus); + return res_OK; } @@ -1185,6 +1244,11 @@ skytraq_read(void) return; } + if(*opt_configure_logging) { + skytraq_configure_logging(); + return; + } + dlbaud = atoi(opt_dlbaud); if (dlbaud != 0 && dlbaud != skytraq_baud) { skytraq_set_baud(dlbaud); diff --git a/gpsbabel/xmldoc/formats/options/skytraq-configlog.xml b/gpsbabel/xmldoc/formats/options/skytraq-configlog.xml new file mode 100644 index 000000000..6aa23eddd --- /dev/null +++ b/gpsbabel/xmldoc/formats/options/skytraq-configlog.xml @@ -0,0 +1,25 @@ + + Set the logging configuration as tmin:tmax:dmin:dmax. + Here tmin and tmax are in seconds, and dmin and dmax in meters. + With dt = time since last log, dx = distance since last log, + and v the current speed, the device logs if + + + (dt > tmin and dx >= dmin and v >= vmin) or dt > tmax or dx > dmax or v > vmax + + + If you use this option, vmin is fixed at 0 and vmax at 65535 km/h. + + + Example. Set the device to log every 6 seconds (or 10km, whichever + happens first!) + + + + Set the logging parameters for Skytraq device + + + gpsbabel -i skytraq,configlog=6:3600:0:10000 -f /dev/ttyUSB0 + + + -- 2.30.2